import _ from 'lodash';
import requestApi from '../requestApi'
import config from '../config'

export default function (props, meta) {
	let pageInfo = props.transferTable.getTablePageInfo(config.orderListArea);
	let data = {
		querycondition: props.search.getAllSearchData(config.searchArea),
		pagecode: config.pagecode,
		pageInfo:{
			"pageIndex":pageInfo.pageIndex || 0,
			"pageSize": pageInfo.pageSize || 10,
		},
		queryAreaCode: config.searchArea, //查询区编码
		oid: meta[config.searchArea].oid, //pub_area 中PK_AREA
		querytype: 'tree'
	}
	let bxdata = window.invoiceListQueryParam
	let bxstatus;
	if(this.state.navTabStatus === '33') {
		bxstatus = 0
	}
	else if(this.state.navTabStatus === '36') {
		bxstatus = 1
	}
	else {
		bxstatus = 2
	}
	// 请求添加表体已关联发票的过滤
	let senddata = {
		bxdata,
		data,
		bxstatus
	}
	const { getCardData } = this.props
	const tableData = getCardData() || []
	const selectedOrderList = []
	for (let row of tableData) {
		if (row && row.values && row.values.pk_ermorder && row.values.pk_ermorder.value) {
			selectedOrderList.push({
				pk_ermorder: row.values.pk_ermorder.value,
			})
		}
	}
	senddata['selectedData'] = selectedOrderList;
	requestApi.getOrderList({
		data: senddata,
		success: res => {
			const pageInfo = _.get(res, 'data.pageInfo', {});
			const data = _.get(res, 'data.data', []);
			if (data) {
				//先取消勾选
				this.props.transferTable.cancelRowsChecked('head', Object.keys(this.orderDeleteList))
				this.orderDeleteList = {}

				data.forEach(item => {
					if (!item.body) {
						item.body = { body: { areacode: 'body', rows: [] } }
					}
				})
				const setData = {
					rows: data,
					pageInfo
				};
				if (pageInfo.pageIndex == 0) {
					setData.allpks = new Array(Number(pageInfo.total));
				}
				this.orderList = data
				data && this.props.transferTable.setTransferTableValue(
					config.orderListArea,
					config.bodysArea,
					setData,
					'pk_ermorder',
					'pk_ermorder_b'
				)
			} else {
				this.props.transferTable.setTransferTableValue(
					config.orderListArea,
					config.bodysArea,
					[],
					'pk_ermorder',
					'pk_ermorder_b'
				)
			}
			
		}
	})

	
}
